package com.ruoyi.web.controller.points;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.points.domain.PointsChangeRecord;
import com.ruoyi.points.service.IPointsChangeRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 积分变动记录Controller
 * 
 * @author 区嘉盛
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/points/points")
@Tag(name = "【积分变动记录】管理")
public class PointsChangeRecordController extends BaseController
{
    @Autowired
    private IPointsChangeRecordService pointsChangeRecordService;

    /**
     * 查询积分变动记录列表
     */
    @Operation(summary = "查询积分变动记录列表")
    @GetMapping("/list")
    public TableDataInfo list(PointsChangeRecord pointsChangeRecord)
    {
        startPage();
        List<PointsChangeRecord> list = pointsChangeRecordService.selectPointsChangeRecordList(pointsChangeRecord);
        return getDataTable(list);
    }

    /**
     * 根据userId查询积分变动记录列表
     */
    @Operation(summary = "根据userId查询积分变动记录列表")
    @GetMapping("/user/{userId}/{type}")
    public TableDataInfo getRecordByUserId(@PathVariable Long userId ,@PathVariable Integer type)
    {
        startPage();
        List<PointsChangeRecord> list = pointsChangeRecordService.getRecordByUserId(userId, type);
        return getDataTable(list);
    }

    /**
     * 导出积分变动记录列表
     */
    @Operation(summary = "导出积分变动记录列表")
    @PreAuthorize("@ss.hasPermi('points:points:export')")
    @Log(title = "积分变动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsChangeRecord pointsChangeRecord)
    {
        List<PointsChangeRecord> list = pointsChangeRecordService.selectPointsChangeRecordList(pointsChangeRecord);
        ExcelUtil<PointsChangeRecord> util = new ExcelUtil<PointsChangeRecord>(PointsChangeRecord.class);
        util.exportExcel(response, list, "积分变动记录数据");
    }

    /**
     * 获取积分变动记录详细信息
     */
    @Operation(summary = "获取积分变动记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsChangeRecordService.selectPointsChangeRecordById(id));
    }

    /**
     * 新增积分变动记录
     */
    @Operation(summary = "新增积分变动记录")
    @Log(title = "积分变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsChangeRecord pointsChangeRecord)
    {
        return toAjax(pointsChangeRecordService.insertPointsChangeRecord(pointsChangeRecord));
    }

    /**
     * 修改积分变动记录
     */
    @Operation(summary = "修改积分变动记录")
    @Log(title = "积分变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsChangeRecord pointsChangeRecord)
    {
        return toAjax(pointsChangeRecordService.updatePointsChangeRecord(pointsChangeRecord));
    }

    /**
     * 删除积分变动记录
     */
    @Operation(summary = "删除积分变动记录")
    @Log(title = "积分变动记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(pointsChangeRecordService.deletePointsChangeRecordByIds(ids));
    }
}
